import socket
import sys
import time
import ast

servicesocket=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
servicesocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
host=socket.gethostname()
port=9999
print("等待连接中")
servicesocket.bind((host,port))
print("等待连接中2")
servicesocket.listen(5)
print("等待连接中3")
ClientSock,addr=servicesocket.accept()
print("等待连接")
while True:
    buf = ClientSock.recv(1024)
    if len(buf):
        buff=str(buf,'utf-8')
        #buff="{'state':1,'mac':'40490f2beddd','rc':'aolidhaosfhcalksfh'}"
        #print(buff)
        buff_dict=ast.literal_eval(buff)
        #print(buff_dict,buff_dict["mac"])
        print ("客服端mac地址:" ,buff_dict['mac'])
        print ("客服端注册码:" ,buff_dict['rc'])
    data = input("验证结果:")
    jieguo="{'验证结果':'"+data+"'}"
    ClientSock.sendall(jieguo.encode('utf-8'))
